<template>
<el-form label-width="80px" ref="form" :model="form" :rules="rules">
  <el-row>
    <el-col :span="22">
      <el-form-item label="奖励" prop="rewardAmount">
        <el-input placeholder="请输入奖励" v-model="form.rewardAmount">
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
    </el-col>
    <el-col :span="22">
      <el-form-item label="惩罚" prop="punishAmount">
        <el-input placeholder="请输入惩罚" v-model="form.punishAmount">
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
    </el-col>
    <el-col :span="22">
      <el-form-item label="备注" prop="remarks">
         <el-input v-model="form.remarks" type="textarea" maxlength="100" />
      </el-form-item>
    </el-col>
  </el-row>
  <el-button type="primary" :disabled="disabled" @click="submit" style="margin: 20px 230px">确认提交</el-button>
</el-form>
</template>
<script>
import { rewardPunishSubmit } from '@/api/packManagement/prePackaged'
export default {
  name: 'RewardsPunishment',
  props: {
    rewardsList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      form: {
        packTaskCodes: this.rewardsList
      },
      disabled: false,
      rules: {
        rewardAmount:[
          { required: true, message: '请输入奖励' },
          { pattern: /^\d+(\.\d{1,2})?$/, message: '请正确输入并保留2位小数' }
        ],
        punishAmount:[
          { required: true, message: '请输入惩罚' },
          { pattern: /^\d+(\.\d{1,2})?$/, message: '请正确输入并保留2位小数' }
        ]
      }
    }
  },
  methods: {
    submit(){
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.disabled = true
          rewardPunishSubmit(this.form).then(res => {
            this.$message.success(res.msg)
          }).finally(() => {
            this.disabled = false
            this.$emit('operationComplete')
          })
        }
      })
    }
  }
}
</script>
